/*
 * perceptron_impl.h
 *
 *  Created on: Feb 28, 2011
 *      Author: tqlong
 */

#ifndef PERCEPTRON_IMPL_H_
#define PERCEPTRON_IMPL_H_

#include "learning_tpl.h"
#include <armadillo>

template <typename T>
void Perceptron<T>::setParameters(const std::vector<double>& params)
{
  if (params.size() > 0) alpha_ = params[0];
}

template <typename T>
double Perceptron<T>::update(const vec_type& x, double y, double p)
{
  double error = 0.5 * (y - p);                        // the delta update rule
  w_ += (alpha_ * error) * x;
  return error;
}

template <typename T>
double Perceptron<T>::predict(const vec_type& x) {
  double y = arma::dot(w_, x);
  this->predict_ = y > 0 ? 1 : -1;
  return this->predict_;
}

#endif /* PERCEPTRON_IMPL_H_ */
